package org.linlinjava.litemall.wx.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallVersionHistory;
import org.linlinjava.litemall.db.service.LitemallVersionHistoryService;
import org.linlinjava.litemall.wx.annotation.LogAnno;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "WxAPP版本API")
@RestController
@RequestMapping("/wx/version")
@RequiredArgsConstructor
public class WxVersionUpgradeController extends ResponseUtil {

    private final LitemallVersionHistoryService versionHistoryService;

    @ApiOperation("查看新版本")
    @GetMapping("/upgrade")
    @LogAnno
    public Response wxUpgrade(){
        //查看是否存在新发布版本
        LitemallVersionHistory newVersion = versionHistoryService.getOne(Wrappers.lambdaQuery(LitemallVersionHistory.class)
                .eq(LitemallVersionHistory::getIsNew, 1));
        return ObjectUtil.isNotNull(newVersion)?ResponseUtil.ok(newVersion):ResponseUtil.fail("There is no updated version");
    }




}
